//加载主页产品list
function LoadPage(page) {
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("ItemForm").innerHTML=xmlhttp.responseText;
		}
	  }
	xmlhttp.open("GET","/ItemForm?page=" + page,true); 
	xmlhttp.send();
}

//检查注册数据
function CheckRegister() {
	Register();
}
//提交注册
function Register() {
	var xmlhttp = new XMLHttpRequest();
	var usercode = document.getElementById("register_usercode").value;
	var username = document.getElementById("register_username").value;
	var password = document.getElementById("register_password").value;
	//alert(username);
	var postdata = "usercode=" + usercode + "&username=" + username + "&password=" + password;
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		//document.getElementById("ItemForm").innerHTML=xmlhttp.responseText;
		if (xmlhttp.responseText == '0') {
			//usercode 重复
			alert('usercode 重复');
			}
		}
	  }
	xmlhttp.open("POST","/register", true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(postdata);
}

//提交登录
function Login() {
	var xmlhttp = new XMLHttpRequest();
	var usercode = document.getElementById("login_usercode").value;
	var password = document.getElementById("login_password").value;
	var autologin = document.getElementById("autologin").checked == true ? 'y' : 'n';
	//alert(username);
	var postdata = "usercode=" + usercode + "&password=" + password + "&autologin=" + autologin;
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		//document.getElementById("ItemForm").innerHTML=xmlhttp.responseText;
		//alert(xmlhttp.responseText);
		if (xmlhttp.responseText == '0') {
			//账号不存在
			alert('账号不存在');
			}
		else if (xmlhttp.responseText == '1') {
			//登录正确
			alert("登录正确");
			}
		else if (xmlhttp.responseText == '2') {
			//密码错误
			alert("密码错误");
			}
		}
		}
	xmlhttp.open("POST","/verify_account", true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(postdata);
}

//提交或修改个人信息
function Profile() {
	var xmlhttp = new XMLHttpRequest();
	var qq = document.getElementById("qq").value;
	var email = document.getElementById("email").value;
	var phone = document.getElementById("phone").value;
	var shortphone = document.getElementById("shortphone").value;
	var password = document.getElementById("password").value;
	var realname = document.getElementById("realname").value;
	var sex_radio = document.getElementsByName("sex");
	var sex = '';
	for(var i = 0; i < sex_radio.length; i++) {
		if(sex_radio[i].checked) {
			sex = sex_radio[i].value;
			}
	}
	var grade_selcet = document.getElementById("grade");
	var grade = grade_selcet[grade_selcet.selectedIndex].text;

	var postdata = "qq=" + qq + "&email=" + email + "&phone=" + phone;
	postdata += "&shortphone=" + shortphone + "&password=" + password;
	postdata += "&realname=" + realname + "&sex=" + sex + "&grade=" + grade;
	
	//alert(postdata);
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		//document.getElementById("ItemForm").innerHTML=xmlhttp.responseText;
		//alert(xmlhttp.responseText);
		}
	}
	xmlhttp.open("POST","/personal", true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(postdata);
}

//提交产品
function SubmitProduct() {
	var xmlhttp = new XMLHttpRequest();
	//alert(window.editor.text());
	var mode = 'sell';
	var mode_radio = document.getElementsByName("mode");
	for(var i = 0; i < mode_radio.length; i++) {
		if(mode_radio[i].checked) {
			mode = mode_radio[i].value;
			}
	}
	var bookname = document.getElementById("bookname").value;
	var original_price = document.getElementById("original_price").value;
	var now_price = document.getElementById("now_price").value;
	var author = document.getElementById("author").value;
	var press = document.getElementById("press").value;
	var publishing_date = document.getElementById("publishing_date").value;
	var fineness_selcet = document.getElementById("fineness");
	var fineness = fineness_selcet[fineness_selcet.selectedIndex].text;
	var isbn = document.getElementById("isbn").value;
	var course = document.getElementById("course").value;

	var rich_text = window.editor.text();
	
	var postdata = "mode=" + mode + "&bookname=" + bookname + "&original_price=" + original_price;
	postdata += "&now_price=" + now_price + "&author=" + author;
	postdata += "&press=" + press + "&publishing_date=" + publishing_date + "&fineness=" + fineness;
	postdata += "&isbn=" + isbn + "&course=" + course + "&rich_text=" + rich_text;
	
	alert(postdata);
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		//document.getElementById("ItemForm").innerHTML=xmlhttp.responseText;
		//alert(xmlhttp.responseText);
		}
	}
	xmlhttp.open("POST","/UploadProduct", true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(postdata);
}

//页码
/*$(function() {
	$("#PageNum").paginate({
		count: 50,
		start: 1,
		display: 10,
		border: false,
		text_color: '#888',
		background_color: '#EEE',
		text_hover_color: 'black',
		background_hover_color: '#CFCFCF',
		onChange : function(page) {
					//alert(page);
					LoadPage(page);
					}
	});	
});
*/

//回到顶部
$(document).ready(function() {
			// Show or hide the sticky footer button
			$(window).scroll(function() {
				if ($(this).scrollTop() > 200) {
					$('.go-top').fadeIn(200);
				} else {
					$('.go-top').fadeOut(200);
				}
			});
			
			// Animate the scroll to top
			$('.go-top').click(function(event) {
				event.preventDefault();
				
				$('html, body').animate({scrollTop: 0}, 300);
			})
		});

		
//登陆的弹窗
 $(function(){
		$('.click').click(function(){
			$('.bg').css({'display':'block'});
			$('.content1').css({'display':'block'});
		});
		$('.bg').click(function(){
			//$('.bg').css({'display':'none'});
			//$('.content').css({'display':'none'});
		});
		$('.click1').click(function(){
			$('.bg').fadeIn(200);
			$('.content1').fadeIn(400);
		});
		$('.bg').click(function(){
			$('.bg').fadeOut(200);
			$('.content1').fadeOut(200);
		});
	});
	

//注册的弹窗
$(function(){
		$('.click').click(function(){
			$('.bg').css({'display':'block'});
			$('.content2').css({'display':'block'});
		});
		$('.bg').click(function(){
			//$('.bg').css({'display':'none'});
			//$('.content').css({'display':'none'});
		});
		$('.click2').click(function(){
			$('.bg').fadeIn(200);
			$('.content2').fadeIn(400);
		});
		$('.bg').click(function(){
			$('.bg').fadeOut(200);
			$('.content2').fadeOut(200);
		});
	});
	
//注册成功后的弹窗
$(function(){
		$('.click').click(function(){
			$('.bg').css({'display':'block'});
			$('.content3').css({'display':'block'});
		});
		$('.bg').click(function(){
			//$('.bg').css({'display':'none'});
			//$('.content').css({'display':'none'});
		});
		$('.click5').click(function(){
			$('.bg').fadeIn(200);
			$('.content3').fadeIn(400);
		});
		$('.bg').click(function(){
			$('.bg').fadeOut(200);
			$('.content3').fadeOut(200);
		});
	});
	
//找回密码的弹窗
$(function(){
		$('.click').click(function(){
			$('.bg').css({'display':'block'});
			$('.content4').css({'display':'block'});
		});
		$('.bg').click(function(){
			//$('.bg').css({'display':'none'});
			//$('.content').css({'display':'none'});
		});
		$('.click6').click(function(){
			$('.bg').fadeIn(200);
			$('.content4').fadeIn(400);
		});
		$('.bg').click(function(){
			$('.bg').fadeOut(200);
			$('.content4').fadeOut(200);
		});
	});

//登陆与注册两弹窗之间切换
//从登陆到注册
$(document).ready(function(){
  $("#login_regist").click(function(){
    $(".content1").fadeOut();
  });
});
//从注册到登陆
$(document).ready(function(){
  $("#regist_login").click(function(){
    $(".content2").fadeOut();
  });
});


//上传封面照片的弹窗
$(function(){
		$('.click').click(function(){
			$('.bg').css({'display':'block'});
			$('.uploadPic').css({'display':'block'});
		});
		$('.bg').click(function(){
			//$('.bg').css({'display':'none'});
			//$('.content').css({'display':'none'});
		});
		$('.click3').click(function(){
			$('.bg').fadeIn(200);
			$('.uploadPic').fadeIn(400);
			$('.uploadPic').css('height', '460px');
			$('.uploadPic').css('width', '600px');
			$('.uploadPic').css('top', '50%');
		});
		$('.bg').click(function(){
			$('.bg').fadeOut(200);
			$('.uploadPic').fadeOut(200);
			//$('.uploadPic').fadeOut(200);
			$('.uploadPic').css('top', '150%');
			$('.uploadPic').css('height', '0px');
			$('.uploadPic').css('width', '0px');
		});
	});
	
$(function(){
		$('.click').click(function(){
			$('.bg').css({'display':'block'});
			$('.uploadIcon').css({'display':'block'});
		});
		$('.bg').click(function(){
			//$('.bg').css({'display':'none'});
			//$('.content').css({'display':'none'});
		});
		$('.click4').click(function(){
			$('.bg').fadeIn(200);
			$('.uploadIcon').css('height', '460px');
			$('.uploadIcon').css('width', '600px');
			$('.uploadIcon').css('top', '50%');
		});
		$('.bg').click(function(){
			$('.bg').fadeOut(200);
			//$('.uploadIcon').fadeOut(200);
			$('.uploadIcon').css('top', '150%');
			$('.uploadIcon').css('height', '0px');
			$('.uploadIcon').css('width', '0px');
		});
	});
	
	
//登陆验证提示
$(document).ready(function(){
	 $("#btn_register").click(function(){
		$("#div1").fadeIn();
	  });
	});



		

